import static org.lwjgl.opengl.GL11.GL_COMPILE;
import static org.lwjgl.opengl.GL11.GL_TRIANGLES;
import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glEnd;
import static org.lwjgl.opengl.GL11.glEndList;
import static org.lwjgl.opengl.GL11.glGenLists;
import static org.lwjgl.opengl.GL11.glNewList;
import static org.lwjgl.opengl.GL11.glNormal3d;
import static org.lwjgl.opengl.GL11.glTexCoord2d;
import static org.lwjgl.opengl.GL11.glVertex3d;

public abstract class DisplayListHelper
{
	public static int makePrismDisplayList(DrawablePrism prism)
	{
		int displayList = startList();
		dispForDrawablePrism(prism);
		endList();
		return displayList;
	}
	
	public static int makeDisplayList(ObjectCoords oc)
	{
		int displayList = startList();
		dispForCoords(oc);
		endList();
		return displayList;
	}
	
	public static int startList()
	{
		int displayList = glGenLists(1);
		glNewList(displayList, GL_COMPILE);
		glBegin(GL_TRIANGLES);
		return displayList;
	}
	
	public static void dispForDrawablePrism(DrawablePrism prism)
	{
		for(int i = 0; i < prism.getCoordinates().getNumFaces(); i++)
		{
			glTexCoord2d(prism.getCoordinates().getTextureForFace(i, 0), prism.getCoordinates().getTextureForFace(i, 1));
			glVertex3d(prism.getCoordinates().getVectorForFace(i, 0), prism.getCoordinates().getVectorForFace(i, 1), prism.getCoordinates().getVectorForFace(i, 2));
			glTexCoord2d(prism.getCoordinates().getTextureForFace(i, 2), prism.getCoordinates().getTextureForFace(i, 3));
			glVertex3d(prism.getCoordinates().getVectorForFace(i, 3), prism.getCoordinates().getVectorForFace(i, 4), prism.getCoordinates().getVectorForFace(i, 5));
			glTexCoord2d(prism.getCoordinates().getTextureForFace(i, 4), prism.getCoordinates().getTextureForFace(i, 5));
			glVertex3d(prism.getCoordinates().getVectorForFace(i, 6), prism.getCoordinates().getVectorForFace(i, 7), prism.getCoordinates().getVectorForFace(i, 8));
		}
	}
	
	public static void dispForPrism(PrismImporter prism)
	{
		for(int i = 0; i < prism.getNumFaces(); i++)
		{
			glTexCoord2d(prism.getTextureForFace(i, 0), prism.getTextureForFace(i, 1));
			glVertex3d(prism.getVectorForFace(i, 0), prism.getVectorForFace(i, 1), prism.getVectorForFace(i, 2));
			glTexCoord2d(prism.getTextureForFace(i, 2), prism.getTextureForFace(i, 3));
			glVertex3d(prism.getVectorForFace(i, 3), prism.getVectorForFace(i, 4), prism.getVectorForFace(i, 5));
			glTexCoord2d(prism.getTextureForFace(i, 4), prism.getTextureForFace(i, 5));
			glVertex3d(prism.getVectorForFace(i, 6), prism.getVectorForFace(i, 7), prism.getVectorForFace(i, 8));
		}
	}
	
	public static void dispForCoords(ObjectCoords oc)
	{
		for(int i = 0; i < oc.getNumFaces(); i++)
		{
			glNormal3d(oc.getNormalForFace(i, 0), oc.getNormalForFace(i, 1), oc.getNormalForFace(i, 2));
			glTexCoord2d(oc.getTextureForFace(i, 0), oc.getTextureForFace(i, 1));
			glVertex3d(oc.getVectorForFace(i, 0), oc.getVectorForFace(i, 1), oc.getVectorForFace(i, 2));
			glNormal3d(oc.getNormalForFace(i, 3), oc.getNormalForFace(i, 4), oc.getNormalForFace(i, 5));
			glTexCoord2d(oc.getTextureForFace(i, 2), oc.getTextureForFace(i, 3));
			glVertex3d(oc.getVectorForFace(i, 3), oc.getVectorForFace(i, 4), oc.getVectorForFace(i, 5));
			glNormal3d(oc.getNormalForFace(i, 6), oc.getNormalForFace(i, 7), oc.getNormalForFace(i, 8));
			glTexCoord2d(oc.getTextureForFace(i, 4), oc.getTextureForFace(i, 5));
			glVertex3d(oc.getVectorForFace(i, 6), oc.getVectorForFace(i, 7), oc.getVectorForFace(i, 8));
		}
	}
	
	public static void endList()
	{
		glEnd();
		glEndList();
	}
}